//
//  ViewController.swift
//  1.0.Introduction
//
//  Created by joker on 15/7/20.
//  Copyright © 2015年 joker. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    //MARK: Defining Constants and Variables in Swift
    func example1()
    {
        let integerValue = 10
        let stringValue = "Swift"
        let doubleValue = 10.0
        println(integerValue)
        println(stringValue)
        println(doubleValue)
    } //example1
    func example2()
    {
        let integerFromDouble = 10.0 as Int
        /*The value of this variable is 10
            because the compiler truncated the value to an integer */
        println(integerFromDouble)
    } //example2
    func example3(){
        var myString = "Swi"
        myString += "ft"
        /* myString is now Swift */
        println(myString)
    } //example3
    
    //MARK: Creating and Using Arrays in Swift
    func example4(){
        let allStrings = ["Swift", "Objective-C"]
        println(allStrings)
    } //example4
    func example5(){
        var allStrings = [String]()
        allStrings.append("Swift")
        allStrings.append("Objective-C")
        /* Our array is now ["Swift", "Objective-C"] */
    } //example5
    func example6(){
        var allStrings = [String]()
        allStrings.append("Swift")
        allStrings.append("Objective-C")
        
        println(allStrings[0])    // printlns out "Swift"
        
        allStrings.insert("C++", atIndex: 0)
        println(allStrings[0]) //printlns out "C++"
    } //example6
    
    //MARK: Defining and Accessing Dictionaries in Swift
    func example7(){
        let allFullNames = [
            "Vandad" : "Nahavandipoor",
            "Andy" : "Oram",
            "Molly" : "Lindstedt"
        ]
        println(allFullNames["Vandad"]) //printlns out "Nahavandipoor"
    } //example7 
    
    func example8(){
        var allFullNames = [
            "Vandad" : "Nahavandipoor",
            "Andy" : "Oram",
            "Molly" : "Lindstedt"
        ]
        
        allFullNames["Rachel"] = "Roumeliotis"
    } //example8
    func example9(){
        let personInformation = [
            "numberOfChildren" : 2,
            "age" : 32,
            "name" : "Random person",
            "job" : "Something cool"
        ] as [String : AnyObject]
        println(personInformation)
    } //example9
    
    //MARK: Groupting Functionality with Classes and Structures in Swift
    func example10(){
        struct Person{
            var firstName, lastName : String
            
            mutating func setFirstNameTo(firstName: String){
                self.firstName = firstName
            }
        }
    } //example10
        
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

